package com.zyd.shiro.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zyd.shiro.business.service.DepartmentService;
import com.zyd.shiro.business.vo.DepartmentConditionVO;
import com.zyd.shiro.persistence.beans.Department;
import com.zyd.shiro.persistence.beans.School;
import com.zyd.shiro.persistence.mapper.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public Department insert(Department entity) {
        Assert.notNull(entity, "Course不可为空！");
        entity.setCreateTime(new Date());
        entity.setUpdateTime(new Date());
        departmentMapper.insert(entity);
        return entity;
    }

    @Override
    public void insertList(List<Department> entities) {

    }

    @Override
    public boolean removeByPrimaryKey(Long primaryKey) {
        return departmentMapper.deleteByPrimaryKey(primaryKey) > 0;
    }

    @Override
    public boolean update(Department entity) {
        return false;
    }

    @Override
    public boolean updateSelective(Department entity) {
        Assert.notNull(entity, "School不可为空！");
        entity.setUpdateTime(new Date());
        return departmentMapper.updateByPrimaryKey(entity) > 0;
    }

    @Override
    public Department getByPrimaryKey(Long primaryKey) {
        Assert.notNull(primaryKey, "PrimaryKey不可为空！");
        Department department = departmentMapper.selectByPrimaryKey(primaryKey);
        return null == department ? null : department;
    }

    @Override
    public Department getOneByEntity(Department entity) {
        return null;
    }

    @Override
    public List<Department> listAll() {
        return null;
    }

    @Override
    public List<Department> listByEntity(Department entity) {
        return null;
    }

    @Override
    public PageInfo<Department> findPageBreakByCondition(DepartmentConditionVO vo) {
        PageHelper.startPage(vo.getPageNumber(), vo.getPageSize());
        List<Department> departments = departmentMapper.findPageBreakByCondition(vo);
        if (CollectionUtils.isEmpty(departments)) {
            return null;
        }
        PageInfo bean = new PageInfo<Department>(departments);
        bean.setList(departments);
        return bean;
    }
}
